<template>
	<view class="dwu-datetime-picker">
		<view class="picker" @click="pickerShow">
			<u-input v-model="selectVal" inputAlign="right" border="none" :readonly="true" :disabled="disabled"
				:placeholder="placeholder"></u-input>
			<view class="arrow-down">
				<image src="@/static/news/arrow_right.png" mode=""></image>
			</view>
		</view>
		<liu-delivery-time day="90" :defaultDay="defaultDay" :defaultTime="defaultTime" :title="placeholder" @change="changeTime" ref="chooseTime"></liu-delivery-time>
	</view>
</template>

<script>
	export default {
		name: "dwu-datetime-picker",
		props: {
			mode: {
				type: String,
				default: 'date'
			},
			placeholder: {
				type: String,
				default: '请选择日期'
			},
			disabled: {
				type: Boolean,
				default: false
			},
			defaultVal: {
				type: String,
				default: ''
			},
		},
		watch: {
			defaultVal(val) {
				console.log(val);
				this.selectVal = val
				this.defaultDay = val.split(' ')[0]
				this.defaultTime = val.split(' ')[1]
				console.log(this.defaultDay);
				console.log(this.defaultTime);
				// this.value1 = Number(val)
			}
		},
		data() {
			return {
				show: false,
				selectVal: '',
				defaultDay: '',
				defaultTime: '',
				// value1: Number(new Date())
			};
		},
		methods: {
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				return value
			},
			pickerShow() {
				if (this.disabled) return
				this.$refs.chooseTime.open()
			},
            //选择的时间
            changeTime(e) {
                this.selectVal = e.value
				this.$emit('onconfirm', e)
            }
		}
	}
</script>

<style lang="less">
	.dwu-datetime-picker {
		.picker {
			display: flex;
			align-items: center;

			.arrow-down {
				display: flex;
				align-items: center;

				image {
					width: 10rpx;
					height: 18rpx;
				}
			}
		}
	}
</style>